package com.learn.factory_bean;

import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.support.ClassPathXmlApplicationContext;

@ComponentScan
public class FactoryBeanApplication {
    public static void main(String[] args) {
        ClassPathXmlApplicationContext classPathXmlApplicationContext = new ClassPathXmlApplicationContext("factory-bean.xml");
        // 取产品：getObject
        System.out.println(classPathXmlApplicationContext.getBean("xmlFactoryBean"));
        // 取工厂
        System.out.println(classPathXmlApplicationContext.getBean("&xmlFactoryBean"));
        /*
         * XMLFactoryBeanImpl.getObject
         * null
         * com.learn.factory_bean.xml.XMLFactoryBeanImpl@4cc451f2
         */
        
        AnnotationConfigApplicationContext annotationConfigApplicationContext = new AnnotationConfigApplicationContext(FactoryBeanApplication.class);
        // 取产品：getObject
        System.out.println(annotationConfigApplicationContext.getBean("annotationFactoryBean"));
        // 取工厂
        System.out.println(annotationConfigApplicationContext.getBean("&annotationFactoryBean"));
        /*
         * AnnotationFactoryBeanImpl.getObject
         * null
         * com.learn.factory_bean.annotation.AnnotationFactoryBeanImpl@6a84a97d
         */
    }
}
